var $LASTLOGIN=[];
window.onload=function(){
	$POSMENU=3;
	new CHECKLOGIN().check();
	new USER().listUser();
}
USER=function(){}
USER.prototype.listUser=function(){
	var fncSuc = XHR.Delegate(this,this.listUserSuc);
	var param = {action:"listUser"};
	new XHR("post",fncSuc).send($PN+"/DoAdmin",param);
}
USER.prototype.listUserSuc=function(r){
	var xml = r.xml;
	if(getRV(xml)){
		var u=xml.getElementsByTagName("user");
		var html = "";
		for(var i=0; i < u.length; i++){
			html+="<div style='padding:3px;cursor:pointer' onClick='viewDetail(\""+u[i].getAttribute("username")+"\")'>"+u[i].getAttribute("username")+"</div>";
			$LASTLOGIN[u[i].getAttribute("username")]=u[i].getAttribute("lastlogin");
		}
		$("userlist").innerHTML = html;
	}
}
USER.prototype.viewDetail=function(userId){
	var fncSuc = XHR.Delegate(this,this.viewDetailSuc);
	var param = {action:"viewSubmited",userId:userId};
	new XHR("post",fncSuc).send($PN+"/DoAdmin",param);
	this.userid = userId;
}
USER.prototype.viewDetailSuc=function(r){
	var xml = r.xml;
	if(getRV(xml)){
		var n=xml.getElementsByTagName("news")[0];
		var html = n.getAttribute("total");
		html = "<div style='font-size:15px;font-weight:bold'>Tổng cộng tin đã đăng: "+html+"</div>"+
								"<div style='font-size:13px;font-weight:bold;padding-top:5px'>Đăng nhập lần cuối: <span style='color:red'>"+$LASTLOGIN[this.userid]+"</span></div>";
		var item = xml.getElementsByTagName("item");
		if(item.length!=0){
			item = item[0];
			html = html+"<div style='font-size:13px;padding-top:5px'>Bài đăng mới nhất: " +
					"<a style='color:blue' target='_blank' href='"+makeLinkViewNews(item.getAttribute("newsid"),item.getAttribute("utitle"))+"'><b>"+item.getAttribute("title")+"</b></a> ("+item.getAttribute("createddate")+")<div>";
		}
		$("udetail").innerHTML=html;
	}
}
function viewDetail(userid){
	new USER().viewDetail(userid);
}